const http = require('http')
const url = require('url')
const path = require('path')
const fileRequst = require('./fileRequest')
const webPath = '../../'
const serverConfig = {
    staticPath:'dist',
    adminStaticPath:'admin'
}

const server = http.createServer((req,res)=>{
    let _path = url.parse(req.url).pathname
    let adminStaticPathReg = new RegExp(`^\/${serverConfig.adminStaticPath}`)
    _path = path.join(__dirname, webPath, adminStaticPathReg.test(_path)?'admin':'dist/', _path)
    fileRequst(_path, req, res, webPath)
})

const port = 2234
const hostname = 'localhost'
server.listen(port,hostname,()=>{
    console.log(`web服务启动完成，服务地址：${hostname}:${port}`)
})